/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller;

import com.thienloc.omap.entity.Partner;
import com.thienloc.omap.session.PartnersFacade;
import com.thienloc.omap.util.JsfUtil;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class PartnerBean implements Serializable {

    @EJB
    private PartnersFacade partnersFacade;
    private Map<String, String> partnerIdMap;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @PostConstruct
    public void init() {
        try {
            List<Partner> partners = partnersFacade.findAll();
            partnerIdMap = new TreeMap<String, String>();
            for (Partner partner : partners) {
                partnerIdMap.put(partner.getCompanyName(), partner.getPartnerId());
            }
        } catch (Exception ex) {
            logger.error("", ex);
            JsfUtil.addErrorMessage("Error getting partners", ex.getMessage());
        }
    }

    public Map<String, String> getPartnerIdMap() {
        return partnerIdMap;
    }
}
